#!/usr/bin/ruby

require File.join(File.dirname(__FILE__), 'exporter.rb')
require File.join(File.dirname(__FILE__), 'importer.rb')
require File.join(File.dirname(__FILE__), 'migrator.rb')

def display_usage
	puts "mc usage:"
	puts "     mc [command] [arguments]"
	puts "     mc import <address of memcache> filename"
	puts "     mc export <address of memcache> filename"
	puts "          will use the time at the import time as filename if filename if not provided"
	puts "     mc migrate <address of source memcache> <address of target memcache"
end

if(ARGV.length < 2)
	display_usage
	exit
end

case ARGV[0]
when "import"
	if(ARGV.length != 3)
		display_usage
		exit
	end

	address = ARGV[1]
	filename = ARGV[2]
	Importer.new(address,filename).import
when "export"
	address = ARGV[1]
	filename = Time.now.strftime("%Y%m%d%H%M") + ".dump"
	if ARGV[2]
		filename = ARGV[2]
	end
	Exporter.new(address,filename).export
when "migrate"
	if ARGV.length != 3
		display_usage
		exit
	end

	srcAddress = ARGV[1]
	targetAddress = ARGV[2]
	Migrator.new(srcAddress,targetAddress).migrate
else
	"Unknow command " + ARGV[0]
	display_usage
	exit
end


